<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux命令," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;diff 命令是 linux上非常重要的工具，用于比较文件的内容，特别是比较两个版本不同的文件以找到改动的地方。diff在命令行中打印每一个行的改动。最新版本的diff还支持二进制文件。diff程序的输出被称为补丁 (patch)，因为Linux系统中还有一个patch程序，可以根据diff的输出将a.">
<meta name="keywords" content="Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 命令- diff">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/38. Linux 命令- diff/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;diff 命令是 linux上非常重要的工具，用于比较文件的内容，特别是比较两个版本不同的文件以找到改动的地方。diff在命令行中打印每一个行的改动。最新版本的diff还支持二进制文件。diff程序的输出被称为补丁 (patch)，因为Linux系统中还有一个patch程序，可以根据diff的输出将a.">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:35:37.618Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 命令- diff">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;diff 命令是 linux上非常重要的工具，用于比较文件的内容，特别是比较两个版本不同的文件以找到改动的地方。diff在命令行中打印每一个行的改动。最新版本的diff还支持二进制文件。diff程序的输出被称为补丁 (patch)，因为Linux系统中还有一个patch程序，可以根据diff的输出将a.">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/38. Linux 命令- diff/"/>





  <title>Linux 命令- diff | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/38. Linux 命令- diff/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 命令- diff</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:57:34+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;diff 命令是 linux上非常重要的工具，用于比较文件的内容，特别是比较两个版本不同的文件以找到改动的地方。diff在命令行中打印每一个行的改动。最新版本的diff还支持二进制文件。diff程序的输出被称为补丁 (patch)，因为Linux系统中还有一个patch程序，可以根据diff的输出将a.c的文件内容更新为b.c。diff是svn、cvs、git等版本控制工具不可或缺的一部分。</p>
<h2 id="1．命令格式"><a href="#1．命令格式" class="headerlink" title="1．命令格式"></a>1．命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">diff [参数] [文件1或目录1] [文件2或目录2]</div></pre></td></tr></table></figure>
<h2 id="2．命令功能"><a href="#2．命令功能" class="headerlink" title="2．命令功能"></a>2．命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;diff命令能比较单个文件或者目录内容。如果指定比较的是文件，则只有当输入为文本文件时才有效。以逐行的方式，比较文本文件的异同处。如果指定比较的是目录的的时候，diff 命令会比较两个目录下名字相同的文本文件。列出不同的二进制文件、公共子目录和只在一个目录出现的文件。</p>
<h2 id="3．命令参数："><a href="#3．命令参数：" class="headerlink" title="3．命令参数："></a>3．命令参数：</h2><ul>
<li><ul>
<li>　指定要显示多少行的文本。此参数必须与-c或-u参数一并使用。</li>
</ul>
</li>
<li>-a或–text 　diff预设只会逐行比较文本文件。</li>
<li>-b或–ignore-space-change 　不检查空格字符的不同。</li>
<li>-B或–ignore-blank-lines 　不检查空白行。</li>
<li>-c 　显示全部内文，并标出不同之处。</li>
<li>-C或–context 　与执行”-c-“指令相同。</li>
<li>-d或–minimal 　使用不同的演算法，以较小的单位来做比较。</li>
<li>-D或ifdef 　此参数的输出格式可用于前置处理器巨集。</li>
<li>-e或–ed 　此参数的输出格式可用于ed的script文件。</li>
<li>-f或-forward-ed 　输出的格式类似ed的script文件，但按照原来文件的顺序来显示不同处。</li>
<li>-H或–speed-large-files 　比较大文件时，可加快速度。</li>
<li>-l或–ignore-matching-lines 　若两个文件在某几行有所不同，而这几行同时都包含了选项中指定的字符或字符串，则不显示这两个文件的差异。</li>
<li>-i或–ignore-case 　不检查大小写的不同。</li>
<li>-l或–paginate 　将结果交由pr程序来分页。</li>
<li>-n或–rcs 　将比较结果以RCS的格式来显示。</li>
<li>-N或–new-file 　在比较目录时，若文件A仅出现在某个目录中，预设会显示：Only in目录：文件A若使用-N参数，则diff会将文件A与一个空白的文件比较。</li>
<li>-p 　若比较的文件为C语言的程序码文件时，显示差异所在的函数名称。</li>
<li>-P或–unidirectional-new-file 　与-N类似，但只有当第二个目录包含了一个第一个目录所没有的文件时，才会将这个文件与空白的文件做比较。</li>
<li>-q或–brief 　仅显示有无差异，不显示详细的信息。</li>
<li>-r或–recursive 　比较子目录中的文件。</li>
<li>-s或–report-identical-files 　若没有发现任何差异，仍然显示信息。</li>
<li>-S或–starting-file 　在比较目录时，从指定的文件开始比较。</li>
<li>-t或–expand-tabs 　在输出时，将tab字符展开。</li>
<li>-T或–initial-tab 　在每行前面加上tab字符以便对齐。</li>
<li>-u,-U或–unified= 　以合并的方式来显示文件内容的不同。</li>
<li>-v或–version 　显示版本信息。</li>
<li>-w或–ignore-all-space 　忽略全部的空格字符。</li>
<li>-W或–width 　在使用-y参数时，指定栏宽。</li>
<li>-x或–exclude 　不比较选项中所指定的文件或目录。</li>
<li>-X或–exclude-from 　您可以将文件或目录类型存成文本文件，然后在=中指定此文本文件。</li>
<li>-y或–side-by-side 　以并列的方式显示文件的异同之处。</li>
<li>–help 　显示帮助。</li>
<li>–left-column 　在使用-y参数时，若两个文件某一行内容相同，则仅在左侧的栏位显示该行内容。</li>
<li>–suppress-common-lines 　在使用-y参数时，仅显示不同之处。</li>
</ul>
<h2 id="4．使用实例："><a href="#4．使用实例：" class="headerlink" title="4．使用实例："></a>4．使用实例：</h2><h3 id="实例1：比较两个文件"><a href="#实例1：比较两个文件" class="headerlink" title="实例1：比较两个文件"></a>实例1：比较两个文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">diff log2014.log log2013.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># diff log2014.log log2013.log </span></div><div class="line">3c3</div><div class="line">&lt; 2014-03</div><div class="line">---</div><div class="line">&gt; 2013-03</div><div class="line">8c8</div><div class="line">&lt; 2013-07</div><div class="line">---</div><div class="line">&gt; 2013-08</div><div class="line">11,12d10</div><div class="line">&lt; 2013-11</div><div class="line">&lt; 2013-12</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;上面的“3c3”和“8c8”表示log2014.log和log20143log文件在3行和第8行内容有所不同；”11,12d10”表示第一个文件比第二个文件多了第11和12行。</p>
<h4 id="diff-的normal-显示格式有三种提示"><a href="#diff-的normal-显示格式有三种提示" class="headerlink" title="diff 的normal 显示格式有三种提示:"></a>diff 的normal 显示格式有三种提示:</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;a - add</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;c - change</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;d - delete </p>
<h3 id="实例2：并排格式输出"><a href="#实例2：并排格式输出" class="headerlink" title="实例2：并排格式输出"></a>实例2：并排格式输出</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">diff log2013.log log2014.log  -y -W 50</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># diff log2014.log log2013.log  -y -W 50</span></div><div class="line">2013-01                 2013-01</div><div class="line">2013-02                 2013-02</div><div class="line">2014-03               | 2013-03</div><div class="line">2013-04                 2013-04</div><div class="line">2013-05                 2013-05</div><div class="line">2013-06                 2013-06</div><div class="line">2013-07                 2013-07</div><div class="line">2013-07               | 2013-08</div><div class="line">2013-09                 2013-09</div><div class="line">2013-10                 2013-10</div><div class="line">2013-11               &lt;</div><div class="line">2013-12               &lt;</div><div class="line">[root@localhost test3]<span class="comment"># diff log2013.log log2014.log  -y -W 50</span></div><div class="line">2013-01                 2013-01</div><div class="line">2013-02                 2013-02</div><div class="line">2013-03               | 2014-03</div><div class="line">2013-04                 2013-04</div><div class="line">2013-05                 2013-05</div><div class="line">2013-06                 2013-06</div><div class="line">2013-07                 2013-07</div><div class="line">2013-08               | 2013-07</div><div class="line">2013-09                 2013-09</div><div class="line">2013-10                 2013-10</div><div class="line">                      &gt; 2013-11</div><div class="line">                      &gt; 2013-12</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“|”表示前后2个文件内容有不同</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“&lt;”表示后面文件比前面文件少了1行内容</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“&gt;”表示后面文件比前面文件多了1行内容</p>
<h3 id="实例3：上下文输出格式"><a href="#实例3：上下文输出格式" class="headerlink" title="实例3：上下文输出格式"></a>实例3：上下文输出格式</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">diff log2013.log log2014.log  -c</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># diff log2013.log log2014.log  -c</span></div><div class="line">*** log2013.log 2012-12-07 16:36:26.000000000 +0800</div><div class="line">--- log2014.log 2012-12-07 18:01:54.000000000 +0800</div><div class="line">***************</div><div class="line">*** 1,10 ****</div><div class="line">  2013-01</div><div class="line">  2013-02</div><div class="line">! 2013-03</div><div class="line">  2013-04</div><div class="line">  2013-05</div><div class="line">  2013-06</div><div class="line">  2013-07</div><div class="line">! 2013-08</div><div class="line">  2013-09</div><div class="line">  2013-10</div><div class="line">--- 1,12 ----</div><div class="line">  2013-01</div><div class="line">  2013-02</div><div class="line">! 2014-03</div><div class="line">  2013-04</div><div class="line">  2013-05</div><div class="line">  2013-06</div><div class="line">  2013-07</div><div class="line">! 2013-07</div><div class="line">  2013-09</div><div class="line">  2013-10</div><div class="line">+ 2013-11</div><div class="line">+ 2013-12[root@localhost test3]<span class="comment"># diff log2014.log log2013.log  -c</span></div><div class="line">*** log2014.log 2012-12-07 18:01:54.000000000 +0800</div><div class="line">--- log2013.log 2012-12-07 16:36:26.000000000 +0800</div><div class="line">***************</div><div class="line">*** 1,12 ****</div><div class="line">  2013-01</div><div class="line">  2013-02</div><div class="line">! 2014-03</div><div class="line">  2013-04</div><div class="line">  2013-05</div><div class="line">  2013-06</div><div class="line">  2013-07</div><div class="line">! 2013-07</div><div class="line">  2013-09</div><div class="line">  2013-10</div><div class="line">- 2013-11</div><div class="line">- 2013-12</div><div class="line">--- 1,10 ----</div><div class="line">  2013-01</div><div class="line">  2013-02</div><div class="line">! 2013-03</div><div class="line">  2013-04</div><div class="line">  2013-05</div><div class="line">  2013-06</div><div class="line">  2013-07</div><div class="line">! 2013-08</div><div class="line">  2013-09</div><div class="line">  2013-10[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这种方式在开头两行作了比较文件的说明，这里有三中特殊字符：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“＋” 比较的文件的后者比前着多一行</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“－” 比较的文件的后者比前着少一行</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;“！” 比较的文件两者有差别的行</p>
<h3 id="实例4：统一格式输出"><a href="#实例4：统一格式输出" class="headerlink" title="实例4：统一格式输出"></a>实例4：统一格式输出</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">diff log2014.log log2013.log  -u</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># diff log2014.log log2013.log  -u</span></div><div class="line">--- log2014.log 2012-12-07 18:01:54.000000000 +0800</div><div class="line">+++ log2013.log 2012-12-07 16:36:26.000000000 +0800</div><div class="line">@@ -1,12 +1,10 @@</div><div class="line"> 2013-01</div><div class="line"> 2013-02</div><div class="line">-2014-03</div><div class="line">+2013-03</div><div class="line"> 2013-04</div><div class="line"> 2013-05</div><div class="line"> 2013-06</div><div class="line"> 2013-07</div><div class="line">-2013-07</div><div class="line">+2013-08</div><div class="line"> 2013-09</div><div class="line"> 2013-10</div><div class="line">-2013-11</div><div class="line">-2013-12</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;它的第一部分，也是文件的基本信息：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;— log2014.log 2012-12-07 18:01:54.000000000 +0800</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;+++ log2013.log 2012-12-07 16:36:26.000000000 +0800</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;”—“表示变动前的文件，”+++”表示变动后的文件。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第二部分，变动的位置用两个@作为起首和结束。</p>
<p>@@ -1,12 +1,10 @@</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;前面的”-1,12”分成三个部分：减号表示第一个文件（即log2014.log），”1”表示第1行，”12”表示连续12行。合在一起，就表示下面是第一个文件从第1行开始的连续12行。同样的，”+1,10”表示变动后，成为第二个文件从第1行开始的连续10行。</p>
<h3 id="实例5：比较文件夹不同"><a href="#实例5：比较文件夹不同" class="headerlink" title="实例5：比较文件夹不同"></a>实例5：比较文件夹不同</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">diff  test3 test6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># diff test3 test6</span></div><div class="line">Only <span class="keyword">in</span> test6: linklog.log</div><div class="line">Only <span class="keyword">in</span> test6: log2012.log</div><div class="line">diff test3/log2013.log test6/log2013.log</div><div class="line">1,10c1,3</div><div class="line">&lt; 2013-01</div><div class="line">&lt; 2013-02</div><div class="line">&lt; 2013-03</div><div class="line">&lt; 2013-04</div><div class="line">&lt; 2013-05</div><div class="line">&lt; 2013-06</div><div class="line">&lt; 2013-07</div><div class="line">&lt; 2013-08</div><div class="line">&lt; 2013-09</div><div class="line">&lt; 2013-10</div><div class="line">---</div><div class="line">&gt; hostnamebaidu=baidu.com</div><div class="line">&gt; hostnamesina=sina.com</div><div class="line">&gt; hostnames=<span class="literal">true</span></div><div class="line">diff test3/log2014.log test6/log2014.log</div><div class="line">1,12d0</div><div class="line">&lt; 2013-01</div><div class="line">&lt; 2013-02</div><div class="line">&lt; 2014-03</div><div class="line">&lt; 2013-04</div><div class="line">&lt; 2013-05</div><div class="line">&lt; 2013-06</div><div class="line">&lt; 2013-07</div><div class="line">&lt; 2013-07</div><div class="line">&lt; 2013-09</div><div class="line">&lt; 2013-10</div><div class="line">&lt; 2013-11</div><div class="line">&lt; 2013-12</div><div class="line">Only <span class="keyword">in</span> test6: log2015.log</div><div class="line">Only <span class="keyword">in</span> test6: log2016.log</div><div class="line">Only <span class="keyword">in</span> test6: log2017.log</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例6：比较两个文件不同，并生产补丁"><a href="#实例6：比较两个文件不同，并生产补丁" class="headerlink" title="实例6：比较两个文件不同，并生产补丁"></a>实例6：比较两个文件不同，并生产补丁</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">diff -ruN log2013.log log2014.log &gt;patch.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># diff -ruN log2013.log log2014.log &gt;patch.log</span></div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 12</div><div class="line">-rw-r--r-- 2 root root  80 12-07 16:36 log2013.log</div><div class="line">-rw-r--r-- 1 root root  96 12-07 18:01 log2014.log</div><div class="line">-rw-r--r-- 1 root root 248 12-07 21:33 patch.log</div><div class="line">[root@localhost test3]<span class="comment"># cat patc.log</span></div><div class="line">cat: patc.log: 没有那个文件或目录</div><div class="line">[root@localhost test3]<span class="comment"># cat patch.log </span></div><div class="line">--- log2013.log 2012-12-07 16:36:26.000000000 +0800</div><div class="line">+++ log2014.log 2012-12-07 18:01:54.000000000 +0800</div><div class="line">@@ -1,10 +1,12 @@</div><div class="line"> 2013-01</div><div class="line"> 2013-02</div><div class="line">-2013-03</div><div class="line">+2014-03</div><div class="line"> 2013-04</div><div class="line"> 2013-05</div><div class="line"> 2013-06</div><div class="line"> 2013-07</div><div class="line">-2013-08</div><div class="line">+2013-07</div><div class="line"> 2013-09</div><div class="line"> 2013-10</div><div class="line">+2013-11</div><div class="line">+2013-12[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例7：打补丁"><a href="#实例7：打补丁" class="headerlink" title="实例7：打补丁"></a>实例7：打补丁</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># cat log2013.log</span></div><div class="line">2013-01</div><div class="line">2013-02</div><div class="line">2013-03</div><div class="line">2013-04</div><div class="line">2013-05</div><div class="line">2013-06</div><div class="line">2013-07</div><div class="line">2013-08</div><div class="line">2013-09</div><div class="line">2013-10[root@localhost test3]<span class="comment"># patch log2013.log patch.log </span></div><div class="line">patching file log2013.log</div><div class="line">[root@localhost test3]<span class="comment"># </span></div><div class="line">[root@localhost test3]<span class="comment"># cat log2013.log </span></div><div class="line">2013-01</div><div class="line">2013-02</div><div class="line">2014-03</div><div class="line">2013-04</div><div class="line">2013-05</div><div class="line">2013-06</div><div class="line">2013-07</div><div class="line">2013-07</div><div class="line">2013-09</div><div class="line">2013-10</div><div class="line">2013-11</div><div class="line">2013-12[root@localhost test3]<span class="comment">#</span></div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux命令/" rel="tag"># Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/13. Linux命令- less/" rel="next" title="Linux 命令- less">
                <i class="fa fa-chevron-left"></i> Linux 命令- less
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/40. Linux 命令- cal/" rel="prev" title="Linux 命令- cal">
                Linux 命令- cal <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1．命令格式"><span class="nav-number">1.</span> <span class="nav-text">1．命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2．命令功能"><span class="nav-number">2.</span> <span class="nav-text">2．命令功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3．命令参数："><span class="nav-number">3.</span> <span class="nav-text">3．命令参数：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4．使用实例："><span class="nav-number">4.</span> <span class="nav-text">4．使用实例：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例1：比较两个文件"><span class="nav-number">4.1.</span> <span class="nav-text">实例1：比较两个文件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#diff-的normal-显示格式有三种提示"><span class="nav-number">4.1.1.</span> <span class="nav-text">diff 的normal 显示格式有三种提示:</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例2：并排格式输出"><span class="nav-number">4.2.</span> <span class="nav-text">实例2：并排格式输出</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例3：上下文输出格式"><span class="nav-number">4.3.</span> <span class="nav-text">实例3：上下文输出格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例4：统一格式输出"><span class="nav-number">4.4.</span> <span class="nav-text">实例4：统一格式输出</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例5：比较文件夹不同"><span class="nav-number">4.5.</span> <span class="nav-text">实例5：比较文件夹不同</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例6：比较两个文件不同，并生产补丁"><span class="nav-number">4.6.</span> <span class="nav-text">实例6：比较两个文件不同，并生产补丁</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例7：打补丁"><span class="nav-number">4.7.</span> <span class="nav-text">实例7：打补丁</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
